package controller

import (
	"encoding/json"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
	"gowork/salesRuleConfiguration/model"
)

type DynamicController struct {
	Ctx  iris.Context
	M *model.Order
}

func (dc *DynamicController)PostInsertorder() mvc.Result{
	var po model.PutOrder
	err := dc.Ctx.ReadForm(&po)
	if err != nil {
		return mvc.Response{
			Object : map[string]interface{}{"message": "参数解析错误", "code":500,},
		}
	}

	if err := json.Unmarshal([]byte(po.Meal), &po.MealList); err == nil{
		recv := dc.M.InsertOrderRule(&po)
		if recv["code"] == "200"{
			return mvc.Response{
				Object : map[string]interface{}{"message": "下单成功", "code":200,},
			}
		}else {
			return mvc.Response{
				Object : map[string]interface{}{"message": "下单失败", "code":400,},
			}
		}
	}else {
		return mvc.Response{
			Object : map[string]interface{}{"message": "反序列化失败", "code":400,},
		}
	}
}